import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class PrimeNumbers {

	public static void main(String[] args) throws IOException {
		BufferedReader input = new BufferedReader(new InputStreamReader(System.in));	
		int number = 0;
		boolean isWrongInput = true;
		boolean nextNumber = true;
		while (nextNumber) {
			do {
				System.out.print("Enter any integer number >1: ");
				try {
				 number = Integer.parseInt(input.readLine());
				}	 catch (java.lang.NumberFormatException e) {
						isWrongInput = true;
					}
				if (number<=1) {
						isWrongInput = true;
					} 	else 	{
								isWrongInput = false;			
								}
				if (isWrongInput) {
					System.out.println("Wrong input.");
				}
			} while (isWrongInput);
			boolean isPrime;
			System.out.println("You've entered: ["+number+"]");
			System.out.print("Prime numbers lower than or equal to ["+number+"]: ");
			
			for (int k=2; k<=number; k++) {
				isPrime = true;
				for (int i=2; i<=k/2; i++) {
					if (k%i == 0) {
						isPrime = false;
					}
				}
				if (isPrime) {
					System.out.print(k+" ");		
				}
			}
			System.out.print("\nEnter one more number? (yes/no): ");
			String askContinue;
			boolean foolCheckAskContinue = true;
			while (foolCheckAskContinue) {
				foolCheckAskContinue = false;
				askContinue = input.readLine();
				if (askContinue.equalsIgnoreCase("yes")||askContinue.equalsIgnoreCase("y")) {
					nextNumber = true;
				} else if (askContinue.equalsIgnoreCase("no")||askContinue.equalsIgnoreCase("n")) {
					nextNumber = false;
				} else {
					System.out.print("yes/no: ");
					foolCheckAskContinue = true;
				}
			}
			System.out.println();
		}	
	}
}
